import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:thinking/config/_.dart';

class EditItem extends StatefulWidget{

  final String val;
  final Function callBack;
  EditItem({Key? key, required this.val,required this.callBack}):super(key: key)  ;

  @override
  _EditItem createState() => _EditItem(val:val,callBack:callBack);
}

class _EditItem extends State<EditItem> with SingleTickerProviderStateMixin{

  _EditItem({required this.val,required this.callBack});

  final String val;
  Function callBack;
  Color textColor = ColorConfig.ThemeColor;
  late AnimationController _animationController;
  late Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 300));
    _animation = Tween(begin: 0.0, end: 1.0).animate(_animationController);
    _animationController.forward();
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return FadeTransition(
      opacity: _animation,
      child: ElevatedButton(
        style: ButtonStyle(
          textStyle: MaterialStateProperty.all(TextStyle(fontSize: 14)),
          backgroundColor:MaterialStateProperty.resolveWith((states) {
            return states.contains(MaterialState.pressed)
                ? ColorConfig.ThemeColor
                : Colors.white;
          }),
          shape:MaterialStateProperty.all(
              RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(8))
              )
          ),
          elevation: MaterialStateProperty.all(
              1
          ),
          side: MaterialStateProperty.all(
              BorderSide(
                width: 1.0,
                color: ColorConfig.ThemeColor,

              )
          ),
          foregroundColor:
          MaterialStateProperty.resolveWith((states) {
            return states.contains(MaterialState.pressed)
                ? Colors.white
                : ColorConfig.ThemeOtherColor;
          }),

        ),
        child: Text(this.val),
        onPressed: (){
          if(_animation.status == AnimationStatus.forward || _animation.status == AnimationStatus.reverse) return;
            callBack();
        },
      )
    );


  }

}